{extend name="common/index" /}

{block name="title"}<title>{$title}</title>{/block}

{block name="action"}
<script type="text/html" id="barDemo">
    {if (!empty($del_url))}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {/if}
    {{#  if(d.status < 2){ }}
    {if (!empty($leave_url))}
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="leave">离职</a>
    {/if}
    {if (!empty($sync_url))}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="sync">同步</a>
    {/if}
    {{#  } }}
</script>
{/block}

<script>

    {block name="param"}

    //初始化参数
    var cols = init_cols({$cols|json_encode|raw});
    var list_url = '{$list_url}';
    var get_tags_user = '{$get_tags_user}';
    var del_url = '{$del_url}';
    var leave_url = '{$leave_url}';
    var sync_url='{$sync_url}'
    {/block}
    {block name="layui_event"}
        if(obj.event === 'leave'){
            layer.confirm('确认将此销售设置为离职状态？', function(index){
                $.ajax({
                    url: leave_url+'?id='+data.id
                    ,data: {"id":data.id,"status":2}
                    ,type: 'DELETE'
                    ,success(res){
                        if (res.code == 0){
                            table.reload("table");
                            layer.msg('设置成功');
                        } else{
                            layer.msg('设置失败');
                        }
                    }
                });
                layer.close(index);
            });
        }
        if(obj.event === 'sync'){
            layer.confirm('确认将此销售同步至全平台？', function(index){
                $.ajax({
                    url: sync_url+'?id='+data.id
                    ,data: {"id":data.id}
                    ,type: 'POST'
                    ,success(res){
                        if (res.code == 0){
                            table.reload("table");
                            layer.msg('同步成功');
                        } else{
                            layer.msg('同步失败');
                        }
                    }
                });
                layer.close(index);
            });
        }
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                $.ajax({
                    url: del_url+'?id='+data.id
                    ,data: {"id":data.id,"status":0}
                    ,type: 'DELETE'
                    ,success(res){
                        if (res.code == 0){
                            table.reload("table");
                            layer.msg('删除成功');
                        } else{
                            layer.msg('删除失败');
                        }
                    }
                });
                layer.close(index);
            });
        }

        {/block}
</script>
